<?php
/**
 * 登录
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/12/20 0020
 * Time: 下午 5:36
 */
require_once '../include.php';
$username = $_POST['username'];
$password = md5($_POST['password']);
$verify = $_POST['verify'];
$verify1 = $_SESSION['verify'];
$autoLogin=$_POST['autoLogin'];#自动登录
if ($verify == $verify1){
    $sql="select * from imooc_admin where username='{$username}' and password='{$password}'";
    $row = checkAdmin($sql);
    if ($row){
        if($autoLogin){
            setcookie("adminId",$row['id'],time()+7*24*3600);#一周之类可以自动登录
            setcookie("adminName",$row['username'],time()+7*24*3600);
        }
        $_SESSION['adminName']=$row['username'];
        $_SESSION['adminId']=$row['id'];
        alertMes("登陆成功","index.php");
    }else{
        alertMes("登陆失败，重新登陆","login.php");#提示内容，跳转地址
    }
}else{
//    echo '<script>alert("验证码错误");</script>';
//    echo '<script>window.location = "login.php";</script>';
    alertMes("验证码错误","login.php");#上下代码等同，alertMes是封装好的函数
}